#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription, TimerAction
from launch.substitutions import LaunchConfiguration
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch_ros.actions import Node
import os
from ament_index_python.packages import get_package_share_directory

def generate_launch_description():
    # 获取包路径
    pkg_dir = get_package_share_directory('fruit_cam')
    
    # 左相机启动文件
    left_camera_launch = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(
            os.path.join(pkg_dir, 'launch', 'left_camera.launch.py')
        ),
        launch_arguments={
            'buffer_size': '5',
            'io_method': 'mmap',
        }.items()
    )
    
    # 右相机启动文件（延迟启动以避免设备冲突）
    right_camera_launch = TimerAction(
        period=2.0,  # 延迟2秒启动右相机
        actions=[
            IncludeLaunchDescription(
                PythonLaunchDescriptionSource(
                    os.path.join(pkg_dir, 'launch', 'right_camera.launch.py')
                ),
                launch_arguments={
                    'buffer_size': '5',
                    'io_method': 'mmap',
                }.items()
            )
        ]
    )
    
    return LaunchDescription([
        # 先启动左相机
        left_camera_launch,
        # 延迟启动右相机
        right_camera_launch,
    ])
